
$(function () {
	$(".myDate").datepick();
	$("#newTireRecord").click(function () {
		$("#tireRecordTable >tbody").append($("#tireRecordTemple >tbody >tr").clone());
	});
	$("#deleteTireRecord").click(function () {
		$("#tireRecordTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	$("#addContract").click(function () {
		if($("#contractTable >tbody >tr").length<4){
			$("#contractTable >tbody").append($("#contractTemple >tbody >tr").clone());
		}
	});
	$("#deleteContract").click(function () {
		$("#contractTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	$("#newTireBrand").click(function () {
		$("#tireBrandTable >tbody").append($("#tireBrandTemple >tbody >tr").clone());
	});
	$("#deleteTireBrand").click(function () {
		$("#tireBrandTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	$("#newTrain").click(function () {
		if($("#trainTable >tbody >tr").length<10){
			$("#trainTable >tbody").append($("#trainTemple >tbody >tr").clone());
			$(".myDate").datepick();
		}
	});
	$("#deleteTrain").click(function () {
		$("#trainTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	$("#formSubmit").click(function () {
		$("#tireRecordTable >tbody >tr").each(function (index) {
			$(this).find(".select").attr("name", $(this).find(".select").attr("name").replace(new RegExp("pTireRecord", "g"), index));
			$(this).find(".size14").attr("name", $(this).find(".size14").attr("name").replace(new RegExp("pTireRecord", "g"), index));
			$(this).find(".size16").attr("name", $(this).find(".size16").attr("name").replace(new RegExp("pTireRecord", "g"), index));
			$(this).find(".size17").attr("name", $(this).find(".size17").attr("name").replace(new RegExp("pTireRecord", "g"), index));
			$(this).find(".size18").attr("name", $(this).find(".size18").attr("name").replace(new RegExp("pTireRecord", "g"), index));
			$(this).find(".sizeTotal").attr("name", $(this).find(".sizeTotal").attr("name").replace(new RegExp("pTireRecord", "g"), index));
		});
		$("#contractTable >tbody >tr").each(function (index) {
			$(this).find(".contractName").attr("name", $(this).find(".contractName").attr("name").replace(new RegExp("pContract", "g"), index));
			$(this).find(".contractPost").attr("name", $(this).find(".contractPost").attr("name").replace(new RegExp("pContract", "g"), index));
			$(this).find(".contractMobile").attr("name", $(this).find(".contractMobile").attr("name").replace(new RegExp("pContract", "g"), index));
		});
		$("#tireBrandTable >tbody >tr").each(function (index) {
			$(this).find(".tireBrand").attr("name", $(this).find(".tireBrand").attr("name").replace(new RegExp("pTireBrand", "g"), index));
			$(this).find(".channel").attr("name", $(this).find(".channel").attr("name").replace(new RegExp("pTireBrand", "g"), index));
			$(this).find(".pay").attr("name", $(this).find(".pay").attr("name").replace(new RegExp("pTireBrand", "g"), index));
			$(this).find(".policy").attr("name", $(this).find(".policy").attr("name").replace(new RegExp("pTireBrand", "g"), index));
		});
		$("#trainTable >tbody >tr").each(function (index) {
			$(this).find(".trainContent").attr("name", $(this).find(".trainContent").attr("name").replace(new RegExp("pTrain", "g"), index));
			$(this).find(".trainDate").attr("name", $(this).find(".trainDate").attr("name").replace(new RegExp("pTrain", "g"), index));
			$(this).find(".trainAddress").attr("name", $(this).find(".trainAddress").attr("name").replace(new RegExp("pTrain", "g"), index));
			$(this).find(".trainTeacher").attr("name", $(this).find(".trainTeacher").attr("name").replace(new RegExp("pTrain", "g"), index));
			$(this).find(".trainPerson").attr("name", $(this).find(".trainPerson").attr("name").replace(new RegExp("pTrain", "g"), index));
			$(this).find(".trainOnJob").attr("name", $(this).find(".trainOnJob").attr("name").replace(new RegExp("pTrain", "g"), index));
			$(this).find(".trainComment").attr("name", $(this).find(".trainComment").attr("name").replace(new RegExp("pTrain", "g"), index));
		});
		$("#submitForm")[0].submit();
	});
});

